package com.zzx.boot.controller;

import com.zzx.boot.emus.IsBuddy;
import com.zzx.boot.entity.Buddy;
import com.zzx.boot.entity.dto.AddBuddy;
import com.zzx.boot.entity.dto.BuddyDto;
import com.zzx.boot.entity.vo.BuddyInfoVo;
import com.zzx.boot.entity.vo.BuddyVo;
import com.zzx.boot.service.BuddyService;
import com.zzx.boot.utils.R;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

@RestController
@RequestMapping("/buddy")
@RequiredArgsConstructor
public class BuddyController {

    private final BuddyService buddyService;

    /**
     * 添加
     * @param buddy
     * @return
     */
    @PostMapping("/add")
    public R addBuddy(@RequestBody  AddBuddy buddy){
        return R.success(buddyService.addBuddy(buddy));
    }

    @GetMapping("/all")
    public R<List<BuddyVo>> buddyListByUserId(){
        return R.success(buddyService.buddyListByUserId());
    }

    /**
     * 获取好友列表
     * @return
     */
    @GetMapping("/list")
    public R<List<BuddyInfoVo>> buddyList() {
        return R.success(buddyService.agreeBuddyList());
    }

    /**
     * 通过id好友信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public R<BuddyInfoVo> buddyInfoById(@PathVariable("id") Long id) {
        BuddyInfoVo info = buddyService.getBuddyInfoById(id);

        return R.success(info);
    }

    /**
     *
     * 更新好友
     * @param buddy
     * @return
     */
    @PutMapping("/update")
    public R update(@RequestBody Buddy buddy){
        boolean boo = buddyService.updateById(buddy);
        return R.success(boo?"修改成功":"修改失败");
    }

    /**
     * 获取显示的好友
     * @return
     */
    @GetMapping("/show/list")
    public R getShowBuddyList(){
        return R.success(buddyService.getShowBuddyList());
    }

    @PostMapping("/show/{id}")
    public R addShowBuddy(@PathVariable("id") Long id){
        return R.success(buddyService.addShowBuddy(id));
    }

}
